<?php
    include_once 'Processing/Users/users.php';
    $users = get_users();
    global $user;
    
    /* Change password */
    if(!isset ($_POST['oldPassword']))
        $_POST['oldPassword'] = '';
    if(!isset ($_POST['newPassword']))
        $_POST['newPassword'] = '';
    if(!isset ($_POST['newPasswordRepeated']))
        $_POST['newPasswordRepeated'] = '';
    /* Add user */
    if(!isset ($_POST['username']))
        $_POST['username'] = '';
    if(!isset ($_POST['password']))
        $_POST['password'] = '';
    if(!isset ($_POST['passwordRepeated']))
        $_POST['passwordRepeated'] = '';

    echo messages(null);
    echo messages('other');
    
    add_mini_help('options');
    MainDesign::h1("Nustatymai");
    MainDesign::viewSectionBegin("Keisti savo slaptažodį");
?>
    <div id="myPassword">
        <form action="index.php?options" method="post">
            <input type="hidden" name="real_action_script" value="Processing/Users/users.php" />
            <input type="hidden" name="function" value="changePassword" />
            <label>Senas slaptažodis<input type="password" name="oldPassword" value="<?php echo $_POST['oldPassword']; ?>" /></label>
            <label>Naujas slaptažodis<input type="password" name="newPassword" value="<?php echo $_POST['newPassword']; ?>" /></label>
            <label>Pakartoti slaptažodį<input type="password" name="newPasswordRepeated" value="<?php echo $_POST['newPasswordRepeated']; ?>" /></label>
            <input type="submit" value="Keisti" />
        </form>
    </div>
<?
    MainDesign::viewSectionEnd('', false);
?>
<script type="text/javascript">
    function deleteUser(username, id) {
        var answer = confirm('Ar tikrai norite i\u0161trinti naudotoją "'+username+'" ?')
	if (answer){
            jQuery('[name="userId"]').first().val(id);
            jQuery('[name="username"]').first().val(username);
            jQuery('#userDeleteForm').submit();
	}
    }
</script>
<form id="userDeleteForm" method="post" action="index.php?options">
    <input type="hidden" name="real_action_script" value="Processing/Users/users.php" />
    <input type="hidden" name="function" value="deleteUser" />
    <input type="hidden" name="userId" value="" />
    <input type="hidden" name="username" value="" />
</form>
<?  
    MainDesign::viewSectionBegin("Esami naudotojai");
?>
    <ol>
    <?
        $sql_result = DB::query("SELECT id, username FROM users");
        while($row = DB::row($sql_result)) {
            list($id, $name) = $row;
            $name = htmlspecialchars($name);
            echo "<li>$name <a href='#' onclick='deleteUser(\"$name\", \"$id\")'>Ištrinti</a></li>";
        }
    ?>
    </ol>
<?
    MainDesign::viewSectionEnd('', false);
    
    MainDesign::viewSectionBegin("Sukurti naują naudotoją");
?>
    <div id="newUser">
        <form action="index.php?options" method="post">
            <input type="hidden" name="real_action_script" value="Processing/Users/users.php" />
            <input type="hidden" name="function" value="newUser" />
            <label>Naudotojo vardas<input type="text" name="username" value="<?php echo $_POST['username']; ?>" /></label>
            <label>Naudotojo slaptažodis<input type="password" name="password" value="<?php echo $_POST['password']; ?>" /></label>
            <label>Pakartoti slaptažodį<input type="password" name="passwordRepeated" value="<?php echo $_POST['passwordRepeated']; ?>" /></label>
            <input type="submit" value="Pridėti" />
        </form>
    </div>
<?
    MainDesign::viewSectionEnd('', false);
